import paddle
from paddleocr import PaddleOCR

while True:
    ocr = PaddleOCR(
        use_doc_orientation_classify=False,
        use_doc_unwarping=False,
        use_textline_orientation=False
    )
    # result = ocr.predict(input="1.jpg")
    file = input('输入文件名：')
    fs = file.split('.')[0]
    result = ocr.predict(input=file)

    for res in result:
        # print(res)
        # res.save_to_img("22.png")
        res.save_to_img(file)
        res.save_to_json(f"{fs}.json")


    print('================')


    import json
    with open(f"{fs}.json", "r", encoding="utf-8") as f:
        data = json.load(f)
    rec_texts = data['rec_texts']
    for r in rec_texts:
        print(r)
    result = ",".join(map(str, rec_texts))
    open(f"{fs}.txt", "w", encoding="utf-8").write(result)
    print('================')

